<?php

/*
 * 全局函数
 */

function I($key, $dft = '') {
    $a = explode('/', trim($key));
    $key = $a[0];
    $type = isset($a[1]) ? $a[1] : '';
    $a = explode('.', $key);
    $n = count($a);
    if ($n == 1) {
        if (isset($_POST[$a[0]])) {
            $dft = $_POST[$a[0]];
        } else {
            isset($_GET[$a[0]]) && $dft = $_GET[$a[0]];
        }
    } elseif ($n == 2) {
        if ($a[0] == 'get') {
            isset($_GET[$a[1]]) && $dft = $_GET[$a[1]];
        } elseif ($a[0] == 'post') {
            isset($_POST[$a[1]]) && $dft = $_POST[$a[1]];
        }
    }
    switch (strtolower($type)) {
        case 'i':
            return intval($dft);
        case 'f':
            return floatval($dft);
        case 'b':
            return !(empty($dft) || $dft == 'no' || $dft == 'false' || $dft == 'fail' || $dft == 'null' || $dft == 'NULL');
        case 'a':
            if (is_string($dft)) {
                return preg_split('#[| ,]+#', $dft);
            }
            if (count($dft) == 1 && $dft === '') {
                $dft = array();
            }
        default:
            return $dft;
    }
    return $dft;
}

function M($db = "test",$tabName="") {
    if (is_array($db)) {
        $conf = $db;
    } else {
        $conf = \Yaf_Application::app()->getConfig()->{$db};
    }
    return new Db\Mysql($conf,$tabName="");
}

function qiuniuToken($dateNumber = 1) {
    include_once APP_PATH . '/application/library/upload.php';
    $upMoth = new upLoad();
    return $upMoth->upFiles($dateNumber);
}

